package com.hongkzh.www.look.media.view.adapter;

/**
 * Created by as on 2018/4/12.
 */

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hongkzh.www.R;

import java.util.ArrayList;

/**
 * 二级目录的 市级 的数据适配器
 * @author Administrator
 *
 */
public class CitySecondAdapter extends BaseAdapter {

    private ArrayList<String> mCityList;
    private Context context;
    private int root_position;
    private LayoutInflater inflater;

    private int selectedPosition = -1;

    public void setSelectedPosition(int selectedPosition) {
        this.selectedPosition = selectedPosition;
    }

    public CitySecondAdapter(Context context, ArrayList<String> sub_items,
                             int position) {
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.mCityList = sub_items;
        this.root_position = position;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return mCityList.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return mCityList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder;
        if (convertView == null) {

            holder = new ViewHolder();
            convertView = (View) inflater.inflate(R.layout.item_trade_listview,
                    parent, false);
            holder.mRootLayout=(LinearLayout)convertView.findViewById(R.id.root_item);
            holder.item_text = (TextView) convertView
                    .findViewById(R.id.item_name_text);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        /**
         * 该项被选中时改变背景色
         */
        if(selectedPosition == position){
//          Drawable item_bg = new ColorDrawable(R.color.sub_list_color);
            holder.mRootLayout.setBackgroundColor(Color.WHITE);
        }else{
//          Drawable item_bg = new ColorDrawable(R.color.sub_list_color);
            holder.mRootLayout.setBackgroundColor(Color.TRANSPARENT);
        }



        holder.item_text.setText(mCityList.get(position));
        return convertView;
    }
    class ViewHolder{
        TextView item_text;
        LinearLayout  mRootLayout;
    }

}
